import 'dart:convert';

import 'package:enterprise_v6_app/app/data/common/choice_bean.dart';
import 'package:enterprise_v6_app/app/data/entities/common/department_user_entity.dart';
import 'package:enterprise_v6_app/generated/json/base/json_field.dart';
import 'package:enterprise_v6_app/generated/json/department_tree_entity.g.dart';
export 'package:enterprise_v6_app/generated/json/department_tree_entity.g.dart';

/// 部门树实体
@JsonSerializable()
class DepartmentTreeEntity extends ChoiceBean {
  DepartmentTreeEntity();

  factory DepartmentTreeEntity.fromJson(Map<String, dynamic> json) => $DepartmentTreeEntityFromJson(json);
  String? pid = '';

  /// 子部门
  List<DepartmentTreeEntity>? children = [];

  /// 部门名称
  String? departmentName = '';

  /// 部门id
  String? id = '';

  /// 是否展开
  bool? isExpand = false;

  /// 是否选中
  bool? isSelected = false;

  /// 当前节点下人员
  List<DepartmentUserEntity>? userList = [];

  Map<String, dynamic> toJson() => $DepartmentTreeEntityToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }

  @override
  String getId() {
    return id!;
  }

  @override
  bool getIsChecked() {
    return isSelected!;
  }

  @override
  String getShowName() {
    return departmentName!;
  }

  @override
  setIsChecked(bool isChecked) {
    isSelected = isChecked;
  }
}
